﻿<!doctype html>
<html>
<!-- InstanceBegin template="/Templates/template1.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta charset="utf-8">
<!-- InstanceBeginEditable name="doctitle" -->
<title>任务管理</title>
<!-- InstanceEndEditable -->
<script type="text/javascript" src="../js/common.js"></script>
<script type="text/javascript" src="../js/checkLogin.js"></script> 
<link href="../css/Pager.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../js/jquery.pager.js"></script>
<script type="text/javascript" src="../js/gbRst.js"></script>
<script type="text/javascript" src="../js/utils.js"></script>
<script type="text/javascript" src="../js/checkLogin.js"></script> 
	<script charset="utf-8" src="../js/find.js"></script>
	<link rel="stylesheet" href="../css/default.css" />
<script type="text/javascript" src="../js/manhuaDate.1.0.js"></script> 
<script type="text/javascript" src="../js/userSelecterNew.js"></script> 
<script type="text/javascript" src="../js/pagination.js"></script> 
<script type="text/javascript" src="../js/customerSelecterNew.js"></script> 
<link href="../css/style.css" type="text/css" rel="stylesheet" />
<script type="text/javascript">
$(function(){
	$(".hideDiv").each(function(){
		addMargin($(this));
	})
	restForm();
	$("input[type='file']").change(function(){
		$(this).prev().prev().val($(this).val())
	})
	$("#dtBegin").val(getToday());
	$("#dtEnd").val(getToday());
});

var shopPageCount=0;
var shopCount=0;
var pageCount=0;
var pageIndex=1;
$(function(){
	$("#shopIsChoosed").click(function(){
		if($("#shopIsChoosed").is(":checked")){
			$("#shopName").attr("disabled",false);
			$("#research").attr("disabled",false);
			
		}else{
			$("#shopName").attr("disabled",true);

		}
	});
	

	$(".hideDiv").each(function(){
		addMargin($(this));
	})
	
});
function bclicks(obj){
	var $first=obj.parent("td").parent("tr").children("td:first");
	var id=$first.html();
	var name=$first.next().html();
	//$("#shopName").children("option").blur();
	getParamToshopS(id,name);
}

function getParamToshopS(id,name){
	var shopflag=$("#shopflag").val();
	if(shopflag==1){
		$("#shopName2").val(name);
		$("#shopId").val(id);
		$("#keyId").html("")
		chooseKeyId();
	}else{
		
	var htm="<option value='"+id+"'>"+name+"</option>";
	$("#shopName").html(htm);
	$("#shopName").val(id);
	
	chooseKeyId2();
	}
	closeShopShow();
}

function closeShopShow(){
	$("#shopShow,#yinying").hide();
	$("#searchName").val("");
}
function InitShopList(shopPageIndex){
	var shopName=$("#searchName").val().replace(/\s/gi,'');
	$.ajax({
		type : "post",
		async:false,
		data :'name='+shopName,
		datatype : "json",
		url : "../shop/find/shopList/" + shopPageIndex + "/5",
		success : function(data) {
			var rst = JSON.parse(data);
			 if(IsEmpty(rst)){
					art.dialog({fixed:true, lock: true,content:"查询出错",icon:'error',ok:true});	
					return false;
					}
					if(rst.state==0){
						$("#shopList tbody tr").remove();

						initShopTable(rst);
						$("table[id='shopList'] tbody tr").each(function(){
							$(this).children("td:last").css("text-align","center").append("<input type='button' class='common_btn' value='选择' onclick='bclicks($(this))'>");

						})	
						if(rst.result.len > 0){
							 var shu = rst.result.len;
							 shopCount = Math.ceil(shu/5);					
							 }else{
									shopCount==0;
							 }
						 $("#shopPager").pager({ pagenumber: ++shopPageIndex, pagecount: shopCount, buttonClickCallback: ShopPageClick });
						 addMargin($("#shopShow"));	
						 }else if(rst.state==1){
						art.dialog({fixed:true, lock: true,content:rst.msg,icon:'error',ok:true});	
					}else{
						checkStateShowErrorMsgAndDealResult(data);
					}
		}	
	});
	
		
	
}
ShopPageClick = function(pageclickednumber) {
    $("#shopPager").pager({ pagenumber: --pageclickednumber, pagecount: shopCount, buttonClickCallback: ShopPageClick });
    $("#result").html("Clicked Page " + pageclickednumber);
    InitShopList(pageclickednumber);
};
function search2(){
	InitShopList(0);
}

function initShopTable(json){
	if(json!=null && json.state==0){
		var params = new Array("id", "name","mp","contact");
		Loadtable(json,params,"shopList");
	}
}
function Loadtable(json, params, tableId){
	var phArray = new Array();
	var count = 0;
	if (params != null) {
		$(params).each(function(pIndex, pData) {
			$.each(json.result.head, function(hIndex, hData) {
				if (pData == hData) {
					phArray[count++] = hIndex;
				}
			});
		});
	}
	
	if (json.result.data != null) {
		$.each(json.result.data, function(index, dt) {
			$("table[id='" + tableId + "']").append("<tr></tr>");
			$(phArray).each(function(phIndex, data) {
				$.each($(dt), function(dtIndex, d) {
					if (dtIndex == data) {
						$("table[id='" + tableId + "'] tr:last").append("<td>" +  (d === null||d == "null" ? " " : d) + "</td>");
					}
				});
			});
		});
		
	}
	

	
}

function showShopList(shopflag){
	$("#shopflag").val(shopflag);
	$("#shopName").blur();
	$("#shopShow,#yinying").show();
	InitShopList(0);
}

function getFucnMenuDetailList(page){
	if(IsEmpty(page)){
		page=1
	}
	var dtBegin = $("#dtBegin").val()
	var dtEnd = $("#dtEnd").val()
	var status = $("#searchStatus").val()
	var remindID  = $("#remindID").val()
	var param={'status':status,'dtCreateEnd':dtEnd,'dtCreateBegin':dtBegin,'type':remindID}

	
	 adList = _findInfo("../taskRemind/find/taskRemindList/"+(page -1)+"/10", param);
	if(adList.state==0){
		 $("#funcMenuList tbody").empty();
		 for(var i = 0;i<adList.result.data.length;i++){
			 var htm="<tr>"
			 		htm+="<td>"+_getStringOfJson(i, adList, "CreateTime")+"</td>";
			 		htm+="<td>"+_getStringOfJson(i, adList, "RemindName")+"</td>";
			 		htm+="<td>"+_getStringOfJson(i, adList, "TaskMemo")+"</td>";
			 		htm+="<td>"+_getStringOfJson(i, adList, "AssignName")+"</td>";
			 		htm+="<td>"+_getStringOfJson(i, adList, "AssignTime")+"</td>";
			 		htm+="<td>"+_getStringOfJson(i, adList, "staName")+"</td>";
			 		var state  = _getIntOfJson(i, adList, "Status");
			 		var id = _getStringOfJson(i, adList, "ID");
			 		if(state==0){
			 			htm +="<td><input class=\"common_btn to_update\" type=\"button\" value=\"指派\" onclick='sendUser("+id+")' ></td>"
			 		}else{
						 htm+="<td><input class=\"common_btn to_update\" type=\"button\" value=\"查看\" onclick='look("+id+")' ></td>"
			 		}
			 		htm+="</tr>"
			 		$("#funcMenuList tbody").append(htm);
		 }
		 _loadPage("pager", page, 10, adList, getFucnMenuDetailList, "NoResult")
		$("#sup").html("共"+adList.result.len+"条");	
		
		 
	}
	
}


function toAdd(){
	$("#doflag").val(1)
	$("#orderDate").val(getToday())
	$("#yinying1,#mainMenu").show();
	
}
function sendUser(id){
	$("#orderDate").val(getToday())
	$("#updateId").val(id);
	$("#doflag").val(2)
	$("#yinying1,#sendUserDiv").show();
}
	
	function restForm(){
		 $(".reset").val("");
		}
	
	function __userSelected(userId,userName){
		var doflag=$("#doflag").val()
		if(doflag==1){
		$("#userId").val(userId);
		$("#userName").val(userName);
		}else{
			$("#userId2").val(userId);
			$("#userName2").val(userName);	
		}
		$("#userListPanel, #userListPanel_yinying").hide();

	}
	
	function __customerSelected(memberId,custname,mp){
		$("#memberId").val(memberId)
		$("#custName").val(custname)
		$("#mp").val(mp)
		$("#customerListPanel, #customerListPanel_yinying").hide();

	}
	
	function saveTask(){
		var memberId = $("#memberId").val();
		var remindId = $("#remindId").val();
		var custName = $("#custName").val();
		var mp = $("#mp").val();
		var lisense = $("#lisense").val();
		var orderDate = $("#orderDate").val();
		var userName = $("#userName").val();
		var userId = $("#userId").val();
		var taskMemo = $("#taskMemo").val();
		if(!checkNull(custName, "客户姓名", "custName")||!checkNull(mp, "客户电话", "mp")||!checkNull(userName, "指派人", "userName")||!checkNull(orderDate, "指派日期", null)||!checkNull(orderDate, "任务描述", "taskMemo")){
			return false;
		}
		
		var heads = new Array("AssignTime","RemindID","TaskMemo","Status","License","CustName","MemberID","ShopId","AssignId","AssignName");
		var datas = new Array(orderDate,remindId,taskMemo,1,lisense,custName,memberId,280000022,userId,userName);
		var json = _getJsonParseInsertStr(heads, datas);
		var dt = _insertInfo("../taskRemind/insert", {'data':json})
		if(IsNotEmpty(dt)&&dt.state==0){
			$("#yinying1,#mainMenu").hide();
			getFucnMenuDetailList(1)

		}
	}
	function updateTask(){
		var id = $("#updateId").val();
		var orderDate = $("#orderDate2").val();
		var userName = $("#userName2").val();
		var userId = $("#userId2").val();
		if(!checkNull(userName, "指派人", "userName")||!checkNull(orderDate, "指派日期", null)){
			return false;
		}
		
		var heads = new Array("AssignTime","Status","AssignId","AssignName","ID");
		var datas = new Array(orderDate,1,userId,userName,id);
		var json = _getJsonParseEditStr(heads, datas);
		var dt = _editInfo("../taskRemind/edit", {'data':json})
		if(IsNotEmpty(dt)&&dt.state==0){
			$("#yinying1,#sendUserDiv").hide();
			getFucnMenuDetailList(1)
		}
	}
	function look(id){
		resultId = id;
		resultIndex = 1;
		getResult(1);
	}
	
	function getResult(page){
		if(IsEmpty(page)){
			resultIndex = 1
		}else{
			resultIndex = page
		}
		var result = _findInfo("../taskRemindResult/find/taskRemindResult/"+(resultIndex - 1)+"/5", {'taskRemindId':resultId})
		if(IsNotEmpty(result)&&result.state==0){
			$("#resultList tbody").empty()
			for ( var i = 0; i < result.result.data.length; i++) {
				var htm="<tr>"
					htm+="<td>"+_getStringOfJson(i, result, "createdTime")+"</td>"
					htm+="<td>"+_getStringOfJson(i, result, "reply")+"</td>"
					htm+="<td>"+_getStringOfJson(i, result, "result")+"</td>"
					htm+="</tr>";
			$("#resultList tbody").append(htm)
			}
			_loadPage("resultPage", resultIndex, 5, result, getResult, null)
			addMargin($("#resultShow"))
			$("#resultShow,#yinying1").show()
		}

	}
</script>


</head>

<body>
<!-- InstanceBeginEditable name="EditRegion3" --> 
<div id="yinying"></div>
<div id="yinying1"></div>

<div id="resultShow" class="hideDiv">
    <div style="float:right;margin-bottom:5px;width:20px;height:20px;line-height:20px;text-align:center;background-color:#eee;margin-bottom:5px;border:1px solid #ccc;" > <span style="cursor: pointer;font-size: 14px;" onclick="$('#resultShow,#yinying1').hide()" >X</span> </div>
    <table   id="resultList" cellpadding="4" cellspacing="0" border="1" width="100%">
    <thead>
    <tr>
    <th>处理时间</th>
    <th>回复客户</th>
    <th>处理结果</th>
    </tr>
    </thead>
    <tbody></tbody>
    </table>
    	<div id="resultPage" class="shopPager"></div>
    </div>
<div id="window_changeff" class="hideDiv setHTML" >
	<textarea id="editIndex" name="editIndex"></textarea>
	<div class="BottomBtn">
        <input type="button" value="确定" class="common_btn" onclick="saveHtml()" >
        <input type="button" value="取消" style="background-color: red;" class="common_btn" onclick="cancelHtml()" >
      </div>
</div>
<div id="shopShow" class="hideDiv">
    <div style="float:right;margin-bottom:5px;width:20px;height:20px;line-height:20px;text-align:center;background-color:#eee;margin-bottom:5px;border:1px solid #ccc;" > <span style="cursor: pointer;font-size: 14px;" onclick="closeShopShow();" >X</span> </div>
    <div class="bottom_search"><div class="serWrapper"><input type="text" id="searchName" class="txt"><strong class="refresh" onclick="$('#searchName').val('')">清空</strong></div><input class="common_btn" type="button" style="width:auto;margin-left:5px;" value="查询" onclick="search2()"></div>
    <table   id="shopList" cellpadding="4" cellspacing="0" border="1" width="100%">
    <thead>
    <tr>
    <th>店面ID</th>
    <th>店面名称</th>
    <th>电话</th>
    <th>操作</th>
    </tr>
    </thead>
    </table>
    	<div id="shopPager"></div>
    	<input type="hidden" id="shopflag" >
    </div>
<script type="text/javascript">
$(function(){
	refreshInput($(".serWrapper"));
		$(this).prev().prev().val($(this).val())
	})

</script>
<div class="member_search publish WX hideDiv" id='mainMenu'>
<input type="hidden"  id = "doflag"  >
<div class="closeTop"><span onclick="closeParent($(this))" class="closeThe"><img src="../images/close.png"></span></div>
            <p><span>
	       任务类型：</span>
       <select id="remindId">
				
			<option value="1">生日提醒</option>
			<option value="2">会员到期</option>
			<option value="4">钢瓶检验提醒</option>
			<option value="5">保险到期提醒</option>
			<option value="6">保养到期提醒</option>
			<option value="7">试乘试驾预约</option>
			<option value="8">服务预约</option>
			<option value="9">保险预约</option>
			<option value="10">二手车评估</option>
			
			</select>
      </p> 
      <p><span>客户姓名：</span>
             <input type="text" id="custName" class="reset">
             <input type="hidden" id="memberId" class="reset">
		<input type="button" class="btn" value="…" onclick="openCustomerListPanel(this)">
      </p>
      <p><span>客户电话：</span>
             <input type="text" id="mp" class="reset">

      </p>
      <p><span>客户车牌号：</span>
             <input type="text" id="lisense" class="reset">

      </p>
 <p>
        <span>指派时间：</span>
        <input type="text" id="orderDate"  class="doubledate">
      </p> 
         <p>
        <span>指派人：</span>
        <input type="hidden" id="userId"  class="reset">
        <input type="text" id="userName"  class="reset">
 	<input type="button" class="btn" value="…" onclick="openUserListPanel(this)">
      </p> 
         <p><span>任务描述：</span>
        &nbsp;<textarea id="taskMemo" style="width: 400px;" class="reset"></textarea>
      </p>  
     
      <div class="BottomBtn">
        <input type="button"  value="确定" onclick="saveTask()" id="save_btn">
      </div>
       </div>
     <div class="member_search publish WX hideDiv" id='sendUserDiv'>
<div class="closeTop"><span onclick="closeParent($(this))" class="closeThe"><img src="../images/close.png"></span></div>
 <p>
        <span>指派时间：</span>
        <input type="text" id="orderDate2"  class="doubledate">
      </p> 
         <p>
        <span>指派人：</span>
        <input type="hidden" id="userId2"  class="reset">
        <input type="hidden" id="updateId"  class="reset">
        <input type="text" id="userName2"  class="reset">
 	<input type="button" class="btn" value="…" onclick="openUserListPanel(this)">
      </p> 
      <div class="BottomBtn">
        <input type="button"  value="确定" onclick="updateTask()" id="save_btn">
      </div>
       </div>  
       
<div class="container" id="container">
  <div class="container_R fr">
    <div class="place">任务管理</div>
    <div class="member_search">
      <p>
       <span>任务类型：</span>
			<select id="remindID">
			<option value="">全部</option>
				<option value="8">看房预约</option>
			
			</select>
       <span>起始日期：</span>
		<input id="dtBegin" class="doubledate" type="text" value="" >
		 <span>截止日期：</span>
		<input id="dtEnd" class="doubledate" type="text" value="">
		<p>
		     <span>分配状态：</span>
			<select id="searchStatus">
			<option value="">所有</option>
			<option value="0">未分配</option>
			</select>
        		<input class="btn" id="research" name="查询" type="button" value="查询" onClick="getFucnMenuDetailList(1)" ></p>
        </div>
       <table width="100%" class="member_list" cellpadding="0" cellspacing="1" border="0" id="funcMenuList">
    	<caption><strong>任务列表       <span id="sup">共0条</span>  </strong><input type="button" class="common_btn" value="增加" onclick="toAdd()"></caption>
    	<thead>
    	<tr>
    		<th >任务日期</th>
        	<th >任务类型</th>
        	<th >任务描述</th>
    		<th >指派人</th>
    		<th >指派时间</th>
        	<th >状态</th>
        	<th >操作</th>
        </tr>
        </thead>
       	<tbody>
       		
       	</tbody>
    </table>
      <div id="NoResult"  class="Nothing" style="text-align:center;display: none;">无符合条件的数据！</div>
    <div id="pager"></div>
  </div>
  <div class="fc"></div>
</div>
<!-- InstanceEndEditable --> 
<script type="text/javascript" src="../js/header.js"></script> 
<script type="text/javascript" src="../js/left.js"></script> 
<script type="text/javascript" src="../js/footer.js"></script> 
<script type="text/javascript">
clearThis("absoluteTxt");
showTab(5,3);
</script>
</body>
<!-- InstanceEnd -->
</html>
